using System;
using MbUnit.Framework;
using DotNetNukeMVPWizard.ProjectConfiguration;

namespace DotNetNukeMVPWizard.Tests
{
    [TestFixture]
    public class TestFolderPathConfiguration
    {
        private const string STR_KeyName = "KeyName";
        private const string STR_NotARealFolder = @"Q:\Not\A\Real\Folder";
        private const string STR_TrailingSlash = @"\";
        private const string STR_C_Windows = @"C:\Windows";
        private const string STR_PathToCSharpCompiler = @"C:\Windows\Microsoft.NET\Framework\v3.5\csc.exe";
        private IConfigurable Actual;

        [SetUp]
        public void SetUp()
        {
            Actual = new FolderPathConfiguration(STR_KeyName);
        }

        #region Test Properties
        // TODO: Add test for FolderPathConfiguration.ErrorMessage

        [Test]
        [Description("Ensure that setting value to null generates an empty string")]
        [Annotation(Gallio.Model.AnnotationType.Info, "Owner: Dan Gilleland")]
        public void FolderPathConfiguration_Set_Value_To_Null_Is_Transformed_To_Empty_String()
        {
            Actual.Value = null;
            Assert.AreEqual(string.Empty, Actual.Value);
        }

        [Test]
        [Description("Ensure that setting value to a path will ensure it has a trailing slash")]
        [Annotation(Gallio.Model.AnnotationType.Info, "Owner: Dan Gilleland")]
        public void FolderPathConfiguration_Set_Value_To_Path_Appends_Trailing_Slash()
        {
            Actual.Value = STR_C_Windows;
            Assert.AreEqual(STR_C_Windows + STR_TrailingSlash, Actual.Value);
        }

        [Test]
        [Description("Ensure that setting value to a path will ensure it has a single trailing slash")]
        [Annotation(Gallio.Model.AnnotationType.Info, "Owner: Dan Gilleland")]
        public void FolderPathConfiguration_Set_Value_To_Path_Appends_Single_Trailing_Slash()
        {
            Actual.Value = STR_C_Windows + STR_TrailingSlash;
            Assert.AreEqual(STR_C_Windows + STR_TrailingSlash, Actual.Value);
        }

        [Test]
        [Description("Ensure that IsValid is false for a non-optional empty string")]
        [Annotation(Gallio.Model.AnnotationType.Info, "Owner: Dan Gilleland")]
        public void FolderPathConfiguration_Gets_IsValid_False_For_Empty_String()
        {
            Assert.IsFalse(Actual.IsValid);
        }

        [Test]
        [Description("Ensure that IsValid is false for a non-optional empty string")]
        [Annotation(Gallio.Model.AnnotationType.Info, "Owner: Dan Gilleland")]
        public void FolderPathConfiguration_Gets_IsValid_False_For_Non_Existing_Path()
        {
            Actual.Value = STR_NotARealFolder;
            Assert.IsFalse(Actual.IsValid);
        }

        [Test]
        [Description("Ensure that IsValid is false for a path to a file rather than a folder")]
        [Annotation(Gallio.Model.AnnotationType.Info, "Owner: Dan Gilleland")]
        public void FolderPathConfiguration_Gets_IsValid_False_For_Path_To_File()
        {
            Actual.Value = STR_PathToCSharpCompiler;
            Assert.IsFalse(Actual.IsValid);
        }

        [Test]
        [Description("Ensure that IsValid is true for an optional empty string")]
        [Annotation(Gallio.Model.AnnotationType.Info, "Owner: Dan Gilleland")]
        public void FolderPathConfiguration_Gets_IsValid_True_For_Optional_And_Empty_String()
        {
            Actual = new FolderPathConfiguration(STR_KeyName, string.Empty, true);
            Assert.IsTrue(Actual.IsValid);
        }

        [Test]
        [Description("Ensure that IsValid is true for a non-empty string")]
        [Annotation(Gallio.Model.AnnotationType.Info, "Owner: Dan Gilleland")]
        public void FolderPathConfiguration_Gets_IsValid_True_For_ValidPath()
        {
            Actual.Value = Environment.CurrentDirectory;
            Assert.IsTrue(Actual.IsValid);
        }
        #endregion
    }
}
